<?php
class Api_Lib_Rsp_UniApp_Page {

    function __construct() {
        $this->_pageConfig = array(
            'addRuku'  => 'addRuku',
            'addChuku' => 'addChuku',
        );
    }

    //入库函数
    function pageBuild($params = array(),& $service){
        $formParams = array();

        if(!$params['pageId']){
            $service->send_user_error('pageId not found');
        }

        //判断当前的对应方法
        if(!isset($this->_pageConfig[$params['pageId']])){
            $service->send_user_error('pageId not in config');
        }

        //判断是否配置再其他class中，如果是需要调用其他类
        $pos = strpos($this->_pageConfig[$params['pageId']], '@');
        if($pos > 0){
            list($ctl ,$action) = explode('@', $this->_pageConfig[$params['pageId']]);
            $class = FLEA::getSingleton($ctl);
            $formParams = $class->$action($params);
        }else{
            $action = $this->_pageConfig[$params['pageId']] ? $this->_pageConfig[$params['pageId']] : $params['pageId'];
            $formParams = $this->$action($params);
        }
        //获取页面的配置

        return $formParams;
    }

    function addRuku($params){
        $modelRuku = FLEA::getSingleton('Model_Sample_Ruku');
        $purposeOptions = $modelRuku->getValuesFiled('purpose');
        $typeOptions = $modelRuku->getTypeValues();
        $gexingOptions = $modelRuku->getOptionsSonFiled('gexing');
        array_unshift($gexingOptions ,array('text'=>'请选择','value'=>''));
        $zuzhiOptions = $modelRuku->getOptionsSonFiled('zuzhi');
        array_unshift($zuzhiOptions ,array('text'=>'请选择','value'=>''));
        $tanliOptions = $modelRuku->getOptionsSonFiled('tanli');
        array_unshift($tanliOptions ,array('text'=>'请选择','value'=>''));

        $modelGongyi = FLEA::getSingleton('Model_Jichu_Gongyi');
        $hzlOptions = $modelGongyi->getOptions();
        //表单渲染配置
        $formParams['formItems'] = array(
            array('type'=>'e7-calendar','title'=>'入库日期','placeholder'=>'','value'=>'','clearable'=>true,'name'=>'rukuDate'),
            array('type'=>'e7-input','title'=>'来源','placeholder'=>'来源','value'=>'','clearable'=>true,'name'=>'reason'),
            array('type'=>'e7-autocompleteStr','title'=>'用途','placeholder'=>'用途','value'=>'','clearable'=>true,'name'=>'purpose','options'=>$purposeOptions),
            array('type'=>'e7-picker-pop','title'=>'选择产品','placeholder'=>'','value'=>'','name'=>'productId','dataKey'=>'productList','marginTop'=>true,'displayKey'=>'proName','url'=>'/pages/component/list2product?dataKey=productList'),
            array('type'=>'e7-input','title'=>'花型颜色','placeholder'=>'花型颜色','value'=>'','clearable'=>true,'name'=>'proDesc'),
            array('type'=>'e7-autocompleteStr','title'=>'样品类型','placeholder'=>'样品类型','value'=>'','clearable'=>true,'name'=>'type','options'=>$typeOptions),
            array('type'=>'e7-picker','title'=>'格型','placeholder'=>'格型','value'=>'','clearable'=>true,'name'=>'gexing','options'=>$gexingOptions),
            array('type'=>'e7-picker','title'=>'组织','placeholder'=>'组织','value'=>'','clearable'=>true,'name'=>'zuzhi','options'=>$zuzhiOptions),
            // array('type'=>'e7-picker','title'=>'弹力','placeholder'=>'弹力','value'=>'','clearable'=>true,'name'=>'tanli','options'=>$tanliOptions),
            array('type'=>'e7-checkbox','title'=>'后整理工艺','placeholder'=>'后整理工艺','value'=>'','clearable'=>true,'name'=>'hzlId','options'=>$hzlOptions),
            array('type'=>'e7-picker-pop','title'=>'选择库位','placeholder'=>'','value'=>'','name'=>'kuweiId','dataKey'=>'kuweiList','displayKey'=>'kuweiName'),
            array('type'=>'e7-input','title'=>'入库数量','placeholder'=>'入库数量','value'=>'','clearable'=>true,'name'=>'cnt'),
            // array('type'=>'e7-input','title'=>'条码','placeholder'=>'留空自动生成;支持[英文数字/-]','value'=>'','clearable'=>true,'name'=>'code'),
            array('type'=>'e7-textarea','title'=>'备注','placeholder'=>'更多说明','value'=>'','name'=>'memo',
                'marginTop'=>true,// 看demo效果
                'autoHeight'=>true,//自适应高度，样式中设置了最高高度是150px;
                // 'max'=>'150'//限制字符长度，注视掉则不限制
            ),
            array('type'=>'e7-image','title'=>'样品图片','value'=>'','name'=>'imageId',
                'limit'=>'5',//图片上传的最多数量
                'maxSize'=>'8',//图片最大值，单位 M，默认不限制
            ),
        );

        //表单验证规则
        $formParams['rules'] = array(
            array('name'=>'productId','checkType'=>'notnull','checkRule'=>'','errorMsg'=>'产品必选'),
            array('name'=>'cnt','checkType'=>'notnull','checkRule'=>'','errorMsg'=>'数量必填'),
        );

        $formParams['submitMethod'] = 'sample.ruku.update';
        //表单数据
        $formParams['title'] = '样品入库';

        //如果有主键信息，则获取对应的数据
        if($params['id']){
            $class = FLEA::getSingleton('Api_Lib_Rsp_Sample_Ruku');
            $detial = $class->getRukuInfo(array('sid'=>$params['id']));
            $detial['hzlId'] = explode(',',$detial['hzlId']);
            $formParams['formData'] = $detial;
        }
        return $formParams;
    }

    function addChuku($params){
        //表单渲染配置
        $formParams['formItems'] = array(
            array('type'=>'e7-input','title'=>'姓名','placeholder'=>'姓名','value'=>'','clearable'=>true,'name'=>'name','marginTop'=>true),
            array('type'=>'e7-input','title'=>'年龄','placeholder'=>'年龄','value'=>'','clearable'=>true,'name'=>'age'),
            array('type'=>'e7-input','title'=>'手机','placeholder'=>'手机','value'=>'','clearable'=>true,'name'=>'tel'),
            array('type'=>'e7-passwd','title'=>'密码','placeholder'=>'密码','value'=>'','clearable'=>true,'name'=>'passwd'),
            array('type'=>'e7-calendar','title'=>'入职日期','value'=>'','name'=>'ruzhiDate',/*'notnull'=>true*/),
            array('type'=>'e7-switch','title'=>'是否开除','value'=>'','name'=>'isFire'),
            array('type'=>'e7-picker','title'=>'性别','value'=>'','name'=>'sex','options'=>array(
                array('text'=>'未知','value'=>'1'),
                array('text'=>'男','value'=>'2'),
                array('text'=>'女','value'=>'3'),
            )),
            array('type'=>'e7-radio','title'=>'使用技术','value'=>'','name'=>'codeType','options'=>array(
                array('text'=>'PHP','value'=>'php'),
                array('text'=>'JAVA','value'=>'java'),
                array('text'=>'C#','value'=>'c#'),
            )),

            array('type'=>'e7-autocomplete','title'=>'可输入可选择文本框','placeholder'=>'可输入可选','value'=>'','clearable'=>true,'name'=>'autoInput','marginTop'=>true,'dataKey'=>'test'),
            array('type'=>'e7-autocompleteStr','title'=>'可输入可选择文本框(静态)','placeholder'=>'可输入可选2','value'=>'','clearable'=>true,'name'=>'StringInput','options'=>array('选项1','选项2','选项3')),
            array('type'=>'e7-picker-pop','title'=>'选择客户','placeholder'=>'','value'=>'','name'=>'clientId','dataKey'=>'clientList'),
            array('type'=>'e7-picker-pop','title'=>'选择产品','placeholder'=>'','value'=>'','name'=>'productId','dataKey'=>'productList'),
            array('type'=>'e7-textarea','title'=>'备注','placeholder'=>'更多说明','value'=>'','name'=>'memo',
                'marginTop'=>true,// 看demo效果
                // 'autoHeight'=>false,//自适应高度，样式中设置了最高高度是150px;
                'max'=>'150'//限制字符长度，注视掉则不限制
            ),
            array('type'=>'e7-image','title'=>'证件照','value'=>'','name'=>'imgCard',
                'limit'=>'6',//图片上传的最多数量
                'maxSize'=>'6',//图片最大值，单位 M，默认不限制
            ),
        );

        //表单验证规则
        $formParams['rules'] = array(
            array('name'=>'name','checkType'=>'string','checkRule'=>'1,4','errorMsg'=>'姓名应为1-4个中文字符'),
            array('name'=>'tel','checkType'=>'phoneno','checkRule'=>'','errorMsg'=>'电话格式错误'),
            array('name'=>'age','checkType'=>'between','checkRule'=>'0,500','errorMsg'=>'年龄不合法'),
        );

        //表单数据
        $formParams['formData'] = array(
            'name'     =>'张思瑞',
            'age'      =>'25',
            'sex'      =>'2',
            // 'memo'     =>'',
            'codeType' =>'java',
            'isFire'   =>true,
            'imgCard'  =>array(
                array('imageId'=>1,'imagePath'=>'http://localhost/vue-element/upload/Images/19101511123413867.jpg'),
            )
        );
        return $formParams;
    }
}

?>